//
//  VisitorLoginView.swift
//  01-微博项目搭建
//
//  Created by Adolph on 15/5/14.
//  Copyright (c) 2015年 Adolph. All rights reserved.
//

import UIKit

protocol VisitorLoginViewDelegate: NSObjectProtocol{

    //选中注册按钮
    func didSelectedRegisterButton()
    
    //选中登入按钮
    func didSelectedLoginButton()
}


class VisitorLoginView: UIView {

    @IBOutlet weak var smallIconView: UIImageView!
   
    @IBOutlet weak var iconImageView: UIImageView!

    @IBOutlet weak var messageLable: UILabel!
    
    ///定义代理属性
    weak var delegate: VisitorLoginViewDelegate?
    
    func setUpInfo(imageName: String, message: String, isHome: Bool = false){
       iconImageView.hidden = !isHome
        
        if isHome {
          iconImageView.image = UIImage(named: imageName)
        }else
         {
            smallIconView.image = UIImage(named: imageName)
        }
        messageLable.text = message
        
        isHome ? startAnimation() : stopAnimation()
    }
    
    
    func startAnimation(){
        
      let anmi = CABasicAnimation(keyPath: "transform.rotation")
      anmi.duration = 20
      anmi.toValue = 2 * M_PI
      anmi.repeatCount = MAXFLOAT
      smallIconView.layer.addAnimation(anmi, forKey: "123456")
        
    }
    
    
    func stopAnimation(){
      
      smallIconView.layer.removeAllAnimations()
    }
    
    @IBAction func register()
    {
        ///使用代理，用户点击这个按钮，交给能处理的类去做
        delegate?.didSelectedRegisterButton()
    }
    
    
    @IBAction func login()
    {
        
        ///使用代理，用户点击这个按钮，交给能处理的类去做
        delegate?.didSelectedLoginButton()
    }
}
